package leetcode;

import java.awt.font.NumericShaper;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LeetCode6 {

    public static void main(String[] args) {
        LeetCode6 leetCode6 = new LeetCode6();
        System.out.println(leetCode6.convert("AB", 1));
    }

    public String convert(String s, int numRows) {
        if (numRows == 1)
            return s;
        StringBuilder sb = new StringBuilder();
        List<List<Character>> dict = new ArrayList<>();
        int column = 0;
        boolean fullColumn = true;
        for (int i = 0; i < numRows; i++) {
            dict.add(new ArrayList<>());
        }
        for (int i = 0; i < s.length(); i++) {
            dict.get(column).add(s.charAt(i));
            if (fullColumn) {
                if (column == numRows - 1) {
                    fullColumn = false;
                    column--;
                } else
                    column++;
            } else {
                if (column == 0) {
                    fullColumn = true;
                    column++;
                } else
                    column--;
            }
        }

        for (List<Character> list : dict) {
            for (Character c : list) {
                sb.append(c);
            }
        }
        return sb.toString();
    }
//------------------------------------------------------------------
}
